.TH rkey 1 "Feb 2015" "open-plc-utils-0.0.3" "Qualcomm Atheros Open Powerline Toolkit"

.SH NAME
rkey - HomePlug AV Random Key Generator

.SH SYNOPSIS
.BR rkey 
.RI [ options ] 
.IR file

.SH DESCRIPTION
Dynamically generate distinct HomePlug AV compliant keys.
A new key is printed on stdout with each program invocation or iteration, unless this is suppressed.
Key computation is seeded using a 64 ASCII character string stored in a user created seedfile.
The program automatically increments the seedfile string to preserve continuity and uniqueness across program invocations, program iterations, console sessions, host reboots and production sites.

.PP
This program is part of the Qualcomm Atheros Powerline Toolkit.
See the \fBAMP\fR man page for an overview and installation instructions.

.SH OPTIONS

.TP
.RB - D
Uses HomePlug AV rules for computing a Device Access Key (DAK) from a pass phrase.
A DAK is 16 bytes expressed as 32 hexadecimal digits.
This option over-rides any \fB-M\fR and \fB-N\fR options previously specified on the command line.

.TP
-\fBL \fIlevel\fR
Set security level.
The security level is encoded into the NID.
Level \fB0\fR enables pushbutton pairing.
Level \fB1\fR disables it.
This option has no effect unless a NID is computed.

.TP
.RB - M
Uses HomePlug AV rules for computing a Network Membership Key (NMK) from a pass phrase.
An NMK is 16 bytes expressed as 32 hexadecimal digits.
This option over-rides any \fB-D\fR or \fB-N\fR options previsously specified on the command line.

.TP
.RB - N
Uses HomePlug AV rules for computing a Network Identification Key (NID) from a pass phrase.
An NID is 7 bytes expressed as 14 hexadecimal digits.
This option over-rides any \fB-D\fR or \fB-M\fR options previously specified on the command line.

.TP
-\fBn \fIcount\fR
The number of keys to generate and print.
This program prints the specified number of distinct keys of the specified type, one key per line.
Normally, program output is directed to a file or a pipe when this option is used.
It is useful for creating a file of random keys.

.TP
.RB - o
Use the \fBold\fR seedfile string.
This option prevents the seedfile string from being incremented before a \fBnew\fR key is computed.
This feature allows additional key types to be computed from the same seedfile string.

.TP
.RB - q
Enable quiet mode which, for this application, has no effect.

.TP
.RB - v
Enable verbose mode which, for this application, prints the pass phrase for each key.

.TP
--\fB?\fR, --\fBhelp\fR
Print program help summary on stdout.
This option takes precedence over other options on the command line.

.TP
\fB-!\fR, \fB--version\fR
Print program version information on stdout.
This option takes precedence over other options on the command line.
Use this option when sending screen dumps to Atheros Technical Support so that they know exactly which version of the Linux Toolkit you are using.

.SH ARGUMENTS

.TP
.BR seedfile
The text file containing the seed string.
This file may be any length but only the first 64 characters are significant.
If it is less than 64 characters then it will be extended to 64 characters after the first use.
The full 64 character string is incremented, character by character, right to left each time this program is run.
The seedfile string is salted differently for each type of key requested and used to seed the SHA256 key engine.
One property of the SHA256 algorithm is that small changes in the seed will produce radically different output having an extremely small chance of collision.

.SH EXAMPLES
The following example shows how to create a seedfile.
The seedfile acts as the seed for the SHA256 algorithm.
The seed is then salted (modified) differently for each type of key generated by this program.
The seedfile string is then incremented and re-written each time the program is executed, unless behaviors is suppressed.
Initially, the seedfile must contain at least one character or an error will occur.

.PP
   # echo "My Company Name, Inc." > secret.key

.PP
The following example prints an SHA256 key on stdout.
An SHA256 key is 256 bits or 32 bytes expressed as 64 hexadecimal digits.
An SHA256 key is the default output when no key type is specified.
SHA256 is a public domain standard, not a HomePlug AV standard.

.PP
   # rkey secret.key
   BFF0F6E3C83CE13829EA7F1F6D25042F4B05052E44C0B801EEA7CD6317F3622E

.PP
The following command prints a new Device Access Key (DAK) on stdout using the seedfile \fBsecret.key\fR as the seed.
The key will be different each time this program is executed because the seedfile string is incremented each time.

.PP
   # rkey -D secret.key
   F084B4E8F6069FF1300C9BDB812367FF

.PP
To observe the seedfile string, use option \fB-v\fR.
Notice that the seedfile string is 64 characters long and that spaces are significant.

.PP
   # rkey -D secret.key -v
   89F96BC11480B0E1A37441397695E676 Qualcomm Atheros, Ocala FL                              [8@Z

.PP
The following command prints a new Network Membership Key (NMK) on stdout, instead of a DAK, using the seedfile \fBsecret.key\fR as the seed.
Of course, one could specify another seedfile.

.PP
   # rkey -M secret.key     
   B59319D7E8157BA001B018669CCEE30D

.PP
The following command prints 10 random SHA256 keys on stdout.
SHA256 keys were printed because no other type of key was specified.
Program output could have been directed to a file or a pipe for further processing.

.PP
   # rkey secret.key -n 10
   780AC153CD47AB01520B5B0246DE7B78584C0413393EDA4430773DED80DDF01A
   C7FF68DB206B1E98B8752CC95296692D45AB3DFA418F5CF5DD13479836FEDD4E
   127C8E27F4C8AC7DB27EC8F977968F64D950830B8D511B798FA5A20BE807A7E1
   79E00DBD57A0E22DCEE2C9CF29F3B7DBA95137BEDC8C76EBE3C32BFFA653D136
   AC9B8DA1B480EF0ECD7A734383DC1B0F3886D0959BAE77F30F1F16C069D2FE4A
   B1F57B211EE774B506106DEC90B7D18FE0328377FCFD9A4D523B632DFAEFF87A
   B1C1C746BDC3E45EBE65FC8D5C15D68F41E9981757024A25A4C3261A154BE6F2
   06E6CCEA8C919162D22CE2ADCB2DDFBDCBB876631CE73F48525EC27E435934E9
   F26C0636C6B2D51956D04AD73DE03BE6D112661040CB23DD74922C6E05EC7E6B
   A62219B0BBABA1DBC444574D0D73A52954847E6DB2BE44441C73E12B9F8EA6E7

.PP
The following three commands use the \fB-o\fR option to prevent the seedfile from being incremented before or after the key is computed.
Notice that a DAK is first generated then regenerated again.
The third command generates an NMK using the same seedfile value used to compute the previous two keys.

.PP
   # rkey -D secret.key
   B12E8BA7B0FF31D107BE15E96EF65B86
   # rkey -oD secret.key
   B12E8BA7B0FF31D107BE15E96EF65B86
   # rkey -oM secret.key
   FAD7EA3713497F2E134299FF1118F6B0

.PP
This utterly useless example demonstrates how to generate 10 identical device access keys by suppressing the normal string increment between each key computation.

.PP
   # rkey -oDn 10 secret.key
   B12E8BA7B0FF31D107BE15E96EF65B86
   B12E8BA7B0FF31D107BE15E96EF65B86
   B12E8BA7B0FF31D107BE15E96EF65B86
   B12E8BA7B0FF31D107BE15E96EF65B86
   B12E8BA7B0FF31D107BE15E96EF65B86
   B12E8BA7B0FF31D107BE15E96EF65B86
   B12E8BA7B0FF31D107BE15E96EF65B86
   B12E8BA7B0FF31D107BE15E96EF65B86
   B12E8BA7B0FF31D107BE15E96EF65B86
   B12E8BA7B0FF31D107BE15E96EF65B86

.PP
This example demonstrates how to assign distinct keys to script variables or insert them on a command line using this program.
Read the GNU \fBbash\fR manual for more information on shell scripting.
See the \fBmodpib\fR man page for an explanation of program options shown.

.PP
   # DAK=$(rkey -D secret.key)
   # NMK=$(rkey -M secret.key)
   # echo DAK=${DAK} NMK=${NMK}
   # modpib -D $(rkey -D secret.key) -N ${NMK}

.SH RECOMMENDATIONS
The seedfile is critical to the continuity and uniqueness of generated keys.
The 64 character string stored in the seedfile is incremented, character by character, right to left, with each file access unless that behavior is suppressed using the \fB-o\fR option.
The SHA256 algorithm generates radially different output given minor changes in this string.
The key space is huge and the probability of collision is statistically small.

.PP
Be aware that two seedfiles containing the same start string will generate the same key sequence.
To minimize the chance of duplicate key values across production lines, each production line should use seedfiles having different start strings.
The length of the start string is not important but it should be different for each production line.
If a seedfile is lost, merely replace it with another one, as though you are opening another production line.

.PP
Mathematically, the shorter the start string the longer it will take for two different seedfiles to coincidentally produce identical output.
From 12 to 24 character is a reasonable length but this is not a restriction.
If you have several production lines, you may want to maintain a record of the start strings used on each line in case a new seedfile must be created.

.SH REFERENCES
See the \fBHomePlug AV Specification\fR for more information on encryption keys, pass phrases and hash algorithms used and standard \fBFIPS180-2 sec 5.3.2\fR for more information on SHA256 encoding.

.SH DISCLAIMER
Qualcomm Atheros reserves the right to modify program names, functionality, input format or output format in future toolkit releases without any obligation to notify or compensate toolkit users.

.SH SEE ALSO
.BR hpavkey ( 1 ),
.BR hpavkeys ( 1 ),
.BR keys ( 1 ),
.BR mac2pw ( 1 ),
.BR mac2pwd ( 1 )

.SH CREDITS
 Charles Maier
]

